package com.ruoyi.site.service.impl;

import java.util.List;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.site.mapper.UserAuthsMapper;
import com.ruoyi.site.domain.UserAuths;
import com.ruoyi.site.service.IUserAuthsService;

/**
 * 用户认证/多渠道登录Service业务层处理
 *
 * @author chuckeytang
 * @date 2025-10-13
 */
@Service
public class UserAuthsServiceImpl implements IUserAuthsService
{
    @Autowired
    private UserAuthsMapper userAuthsMapper;

    /**
     * 查询用户认证信息
     */
    @Override
    public UserAuths selectUserAuthsByAuthId(Long authId)
    {
        return userAuthsMapper.selectUserAuthsByAuthId(authId);
    }

    /**
     * 根据登录标识和类型查询用户认证信息 (核心鉴权查询)
     */
    @Override
    public UserAuths selectUserAuthsByIdentifier(String identityType, String identifier) {
        return userAuthsMapper.selectUserAuthsByIdentifier(identityType, identifier);
    }

    /**
     * 查询用户认证列表
     */
    @Override
    public List<UserAuths> selectUserAuthsList(UserAuths userAuths)
    {
        return userAuthsMapper.selectUserAuthsList(userAuths);
    }

    /**
     * 新增用户认证
     */
    @Override
    public int insertUserAuths(UserAuths userAuths)
    {
        // 确保设置创建时间
        if (userAuths.getCreatedAt() == null) {
            userAuths.setCreatedAt(new Date());
        }
        if (userAuths.getUpdatedAt() == null) {
            userAuths.setUpdatedAt(new Date());
        }
        return userAuthsMapper.insertUserAuths(userAuths);
    }

    /**
     * 修改用户认证
     */
    @Override
    public int updateUserAuths(UserAuths userAuths)
    {
        userAuths.setUpdatedAt(new Date());
        return userAuthsMapper.updateUserAuths(userAuths);
    }

    /**
     * 批量删除用户认证
     */
    @Override
    public int deleteUserAuthsByAuthIds(Long[] authIds)
    {
        return userAuthsMapper.deleteUserAuthsByAuthIds(authIds);
    }

    /**
     * 删除用户认证信息
     */
    @Override
    public int deleteUserAuthsByAuthId(Long authId)
    {
        return userAuthsMapper.deleteUserAuthsByAuthId(authId);
    }
}